﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using WaterRevenueMS.Componnent.Common;

using WaterRevenueMS.Componnent.Entities.BasicSet;
using WaterRevenueMS.Core.Repository.BasicSet;
using WaterRevenueMS.Domain.ViewModels.BasicSet;

namespace WaterRevenueMS.Core.Service.BasicSet.Impl
{
    [Export(typeof(IConsumptionAbnormalService))]
    public class ConsumptionAbnormalService : CoreServiceBase, IConsumptionAbnormalService
    {
        [Import]
        public IConsumptionAbnormalRepository ConsumptionAbnormalRepository { get; set; }

        public IQueryable<ConsumptionAbnormal> ConsumptionAbnormals
        {
            get { return ConsumptionAbnormalRepository.Entities; }
        }
        public OperationResult Insert(Domain.ViewModels.BasicSet.ConsumptionAbnormal.ConsumptionAbnormalModel model)
        {
            var entity = new ConsumptionAbnormal
            {
                Yi_CGZ = model.Yi_CGZ,
                Xia_XBJ = Convert.ToByte(model.Xia_XBJValue != 0 ? model.Xia_XBJValue : 0),
                Yong_LXX = model.Yong_LXX,
                Xia_XBFB = model.Xia_XBFB,
                Xia_XGZ =model.Xia_XGZ,
                CreateDT = DateTime.Now,
                Shang_XBJ = Convert.ToByte(model.Shang_XBJValue != 0 ? model.Shang_XBJValue : 0),
                Yong_LSX = model.Yong_LSX,
                Shang_XBFB = model.Shang_XBFB,
                Shang_XGZ = model.Shang_XGZ,
                
                ReviseDT = DateTime.Now

            };
            ConsumptionAbnormalRepository.Insert(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public OperationResult Update(Domain.ViewModels.BasicSet.ConsumptionAbnormal.ConsumptionAbnormalModel model)
        {
            var entity = new ConsumptionAbnormal
            {
                Id=model.Id,
                Yi_CGZ = model.Yi_CGZ,
                Xia_XBJ = Convert.ToByte(model.Xia_XBJValue != 0 ? model.Xia_XBJValue : 0),
                Yong_LXX = model.Yong_LXX,
                Xia_XBFB = model.Xia_XBFB,
                Xia_XGZ = model.Xia_XGZ,
                ReviseDT = DateTime.Now,
                Shang_XBJ = Convert.ToByte(model.Shang_XBJValue != 0 ? model.Shang_XBJValue : 0),
                Yong_LSX = model.Yong_LSX,
                Shang_XBFB = model.Shang_XBFB,
                Shang_XGZ = model.Shang_XGZ

            };
            ConsumptionAbnormalRepository.Update(entity);
            return new OperationResult(OperationResultType.Success, "更新成功");
        }

        public OperationResult Delete(int Id)
        {
            var model = ConsumptionAbnormals.FirstOrDefault(t => t.Id == Id);
            model.IsDeleted = true;

            ConsumptionAbnormalRepository.Delete(model);
            return new OperationResult(OperationResultType.Success, "删除成功");
        }
    }
}
